﻿#region Copyright & License
//
// Project: Quark Framework
// Project site: http://quark.codeplex.com
// See the copyright statement on the project site for more details.
//
// Licensed to the Apache Software Foundation (ASF) under one or more 
// contributor license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright ownership. 
// The ASF licenses this file to you under the Apache License, Version 2.0
// (the "License"); you may not use this file except in compliance with 
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quark.Framework.Exceptions;

namespace Quark.Framework
{
    /// <summary>
    /// 通用组件接口
    /// </summary>
    public interface IQuarkComponent : IIdentifiable, IContextualizable<IQuarkComponentContext>, ILookupable, IDisposable
    {
        /// <summary>
        /// 获取当前组件实例的唯一实例ID
        /// </summary>
        Guid ComponentInstanceId { get; }
    }

    /// <summary>
    /// 通用组件上下文接口
    /// </summary>
    public interface IQuarkComponentContext : IQuarkContext
    {
        /// <summary>
        /// 在当前上下文所驻留的容器实例中查找一个指定类型的组件实例，
        /// 等同于对componentInstanceId参数传入<see cref="Guid.Empty"/>的<see cref="IQuarkComponentContext.LookupComponent{T}(Guid)"/>方法调用
        /// </summary>
        /// <typeparam name="TComponent">要查找的组件类型</typeparam>
        /// <returns>返回查找组件的实例</returns>
        /// <exception cref="InvalidNamingException"><typeparamref name="TComponent"/>组件类型未在当前上下文驻留的容器实例中注册</exception>
        /// <exception cref="LookupException">查找组件实例过程发生异常，内部抛出的异常统一以<see cref="LookupException"/>作为异常封装</exception>
        /// <threadsafety/>
        TComponent LookupComponent<TComponent>() where TComponent : class, IQuarkComponent;

        /// <summary>
        /// 在当前上下文所驻留的容器实例中查找一个指定类型且实例ID为<paramref name="componentInstanceId"/>的组件实例，
        /// 等同于对constraints参数传入<paramref name="componentInstanceId"/>，且scope参数传入"{container}"的<see cref="IQuarkContext.Lookup{T}(string, object, string)"/>方法调用
        /// </summary>
        /// <typeparam name="TComponent">要查找的组件类型</typeparam>
        /// <param name="componentInstanceId">要查找的组件实例的实例ID，传入<see cref="Guid.Empty"/>表示没有实例ID条件限制</param>
        /// <returns>返回查找组件的实例</returns>
        /// <exception cref="InvalidNamingException"><typeparamref name="TComponent"/>组件类型未在当前上下文驻留的容器实例中注册</exception>
        /// <exception cref="LookupException">查找组件实例过程发生异常，内部抛出的异常统一以<see cref="LookupException"/>作为异常封装</exception>
        /// <threadsafety/>
        TComponent LookupComponent<TComponent>(Guid componentInstanceId) where TComponent : class, IQuarkComponent;
    }
}
